package com.pda.gongpin.presenter;

import com.pda.gongpin.bean.ShipmentsDetailsBean;
import com.pda.gongpin.bean.ShipmentsListBean;
import com.pda.gongpin.bean.request.DeliveryNoRequest;
import com.pda.gongpin.contract.ShipmentsContract;
import com.pda.gongpin.contract.ShipmentsListContract;
import com.pda.gongpin.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class ShipmentsPresenter extends BasePresenter<ShipmentsContract .View> implements ShipmentsContract.Presenter {

    @Override
    public void shipmentsManifest(DeliveryNoRequest body) {
        NetUtils.geApi().shipmentsManifest(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<ShipmentsDetailsBean>>() {
                    @Override
                    public void accept(BaseAppEntity<ShipmentsDetailsBean> shipmentsListBeanBaseAppEntity) throws Exception {
                        getView().setData(shipmentsListBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void shipments(DeliveryNoRequest body) {
        NetUtils.geApi().shipments(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<ShipmentsDetailsBean>>() {
                    @Override
                    public void accept(BaseAppEntity<ShipmentsDetailsBean> shipmentsListBeanBaseAppEntity) throws Exception {
                        getView().showMessage(shipmentsListBeanBaseAppEntity.getMessage());
                        getView().finishActivity();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

}
